package com.liukai.bishe.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.liukai.bishe.R;
import com.liukai.bishe.model.doman.transaction.TransactionUseTime;
import com.liukai.bishe.utils.DateUtils;
import com.liukai.bishe.utils.ToastUtil;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

public class RecordRecyclerViewAdapter extends RecyclerView.Adapter<RecordRecyclerViewAdapter.RecordViewHolder> {


    private final Context mContext;
    private List<TransactionUseTime> mTransactionUseTimeList;

    public RecordRecyclerViewAdapter(Context context, List<TransactionUseTime> transactionUseTimeRecordList) {
        this.mContext = context;
        this.mTransactionUseTimeList = transactionUseTimeRecordList;
//        for (TransactionUseTime transactionUseTime : mTransactionUseTimeList) {
//
//            ToastUtil.log(mContext,transactionUseTime.toString());
//
//        }
    }

    @NonNull
    @Override
    public RecordViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(),R.layout.item_recyclerview_record,null);
        return new RecordViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecordViewHolder holder, int position) {
        TransactionUseTime transactionUseTime = mTransactionUseTimeList.get(position);
        String starttime = DateUtils.timeMillisToTime("HH:mm",transactionUseTime.getStarttime());
        ToastUtil.log(mContext,starttime);
        if (starttime.equals("") || starttime != null) {
            holder.startTime.setText(starttime);
        }
        String stoptime = DateUtils.timeMillisToTime("HH:mm",transactionUseTime.getStoptime());
        ToastUtil.log(mContext,starttime);
        if (stoptime.equals("") || stoptime != null) {
            holder.stopTime.setText(stoptime);
        }
        holder.stopTime.setText(DateUtils.timeMillisToTime("HH:mm",transactionUseTime.getStoptime()));
        holder.tvTitle.setText(transactionUseTime.getTransactionname());
//        holder.tvHarvest.setText(transactionUseTime.getHarvest());
        holder.tvThisTime.setText(DateUtils.longTimeToMinuties(Long.valueOf(transactionUseTime.getThistotaltime())) + "分钟");
    }

//    private String getTotalTime(){
//        String transactionUserNames[] = new String[mTransactionUseTimeList.size()];
//        int i = 0;
//        for (TransactionUseTime transactionUseTime : mTransactionUseTimeList) {
//
//            String transactionUserName = transactionUseTime.getTransactionname();
//            int j;
//            for (j = 0;j <transactionUserNames.length;j ++){
//                if (transactionUserNames[j].equals(transactionUserName)){
//
//                }
//            }
//            transactionUserNames[i] = transactionUserName;
//
//
//        }
//    }

    @Override
    public int getItemCount() {
        return mTransactionUseTimeList.size();
    }

    class RecordViewHolder extends RecyclerView.ViewHolder{

        @BindView(R.id.tvTitle)
        public TextView tvTitle;

        @BindView(R.id.startTime)
        public TextView startTime;

        @BindView(R.id.stopTime)
        public TextView stopTime;

        @BindView(R.id.tvHarvest)
        public TextView tvHarvest;

        @BindView(R.id.tvThisTime)
        public TextView tvThisTime;

        @BindView(R.id.tvPercent)
        public TextView tvPercent;

        public RecordViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }

    }

}
